package com.daffodil.workable.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.daffodil.core.util.HqlUtils;
import com.daffodil.core.dao.JpaDao;
import com.daffodil.core.entity.Query;
import com.daffodil.workable.entity.WorkableLine;
import com.daffodil.workable.service.IWorkableLineService;

/**
 * -连线信息Service接口业务实现层
 * @author yweijian
 * @date 2022-04-07
 * @version 1.0
 * @description
 */
@Service
public class WorkableLineServiceImpl implements IWorkableLineService {

    @Autowired
    private JpaDao<String> jpaDao;

    @Override
    public List<WorkableLine> selectWorkableLineList(Query<WorkableLine> query) {
        StringBuffer hql = new StringBuffer("from WorkableLine where 1=1 ");
        List<Object> paras = new ArrayList<Object>();
        HqlUtils.createHql(hql, paras, query);
        return jpaDao.search(hql.toString(), paras, WorkableLine.class, query.getPage());
    }

    @Override
    public WorkableLine selectWorkableLineById(String id) {
        return jpaDao.find(WorkableLine.class, id);
    }

    @Override
    @Transactional
    public void insertWorkableLine(WorkableLine workableLine) {
        jpaDao.save(workableLine);
    }

    @Override
    @Transactional
    public void updateWorkableLine(WorkableLine workableLine) {
        jpaDao.update(workableLine);
    }

    @Override
    @Transactional
    public void deleteWorkableLineByIds(String[] ids) {
        jpaDao.delete(WorkableLine.class, ids);
    }

    @Override
    public WorkableLine selectWorkableLine(Query<WorkableLine> query) {
        StringBuffer hql = new StringBuffer("from WorkableLine where 1=1 ");
        List<Object> paras = new ArrayList<Object>();
        HqlUtils.createHql(hql, paras, query);
        return jpaDao.find(hql.toString(), paras, WorkableLine.class);
    }

    @Override
    public List<WorkableLine> selectWorkableLineListByTaskId(String taskId) {
        return jpaDao.search("from WorkableLine where taskId = ?", taskId, WorkableLine.class);
    }

}
